<?php

	$failed = false;
	$form = new htmlForm('user');
	
	if ($form->isCancel())
		fgsBase::redirect('register');
	
	$form->addField(tr('Login'), 'login', 'text', true);
	$form->addField(tr('Password'), 'password', 'password');
	$form->addField(tr('Password (repeat)'), 'password2', 'password');
	$form->addField(tr('Email'), 'email', 'text', true, 'email');
	$form->addField(tr('Website'), 'website', 'text');
	$form->addSubmit(tr('Submit'));

	if ($form->get('password') != $form->get('password2')) {
		$form->valid = false;
		$form->set('password', '');
		$form->set('password2', '');
	}

	// add user if post is good
	if ($form->isPost() && $form->isValid()) {
		$login = $form->get('login');
		$email = $form->get('email');
		$website = $form->get('website');
		$is_deleted = false;
		$is_admin = false;

		$password = $form->get('password');
		$password2 = $form->get('password2');
		if (!empty($password))
			$password = md5($password);
		else
			$password = $user['password'];

		$avatar = $user['avatar'];
		
		if (fgsUsers::add($login, $password, $email, $website, $avatar, $is_deleted, $is_admin)) 
			fgsBase::redirect('register', array('ok'));
		else 
			$failed = true;
	}
	
?>
